package com.teziyou.commodity.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.thrift.TException;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.mytravel.commodityBridge.service.TicketInfoService;
import com.mytravel.commodityBridge.service.bean.Distributor;
import com.mytravel.commodityBridge.service.bean.OnSaleTicket;
import com.mytravel.commodityBridge.service.bean.TicketAds;
import com.mytravel.commodityBridge.service.bean.TicketInfo;
import com.teziyou.commodity.core.thrift.ConnectionManager;

@SuppressWarnings("rawtypes")
@Service
//public class TicketService extends TicketInfoService.Client {

public class TicketService {
	
	@Resource(name="productConnectionManager")
	private ConnectionManager connectionManager;
	
	private TicketInfoService.Client client;

	public List findTicketsByPage(Map<String, String> paramMap) {
		try {
			return JSON.parseArray(client.findTicketsByPage(paramMap));
		} catch (TException e) {
			throw new RuntimeException(e);
		}
	}

	public int findTicketsByPageCount(Map<String, String> condition) {
		try {
			return client.findTicketsByPageCount(condition);
		} catch (TException e) {
			throw new RuntimeException(e);
		}
	}

	public boolean addTicketInfo(TicketInfo info) {
		try {
			return client.addTicketInfo(info);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean editTicketInfo(TicketInfo info) {
		try {
			return client.editTicketInfo(info);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public void addDistributor(Distributor bean) {
		System.err.println(bean);
		try {
			client.addDistributor(bean);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	public Map getDistributorStrById(long id) {
		try {
			return JSON.parseObject(client.getDistributorStrById(id));
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List findDistributorPage(Map<String, String> paramMap) {
		try {
			return JSON.parseArray(client.findDistributorPage(paramMap));
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int findDistributorCount(Map<String, String> paramMap) {
		try {
			return client.findDistributorCount(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean deleteTicketById(long id) {
		try {
			return client.deleteTicketById(id);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List findOnSaleTicketByPage(Map<String, String> paramMap) {
		try {
			return JSON.parseArray(client.findOnSaleTicketByPage(paramMap));
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int findOnSaleTicketByPageCount(Map<String, String> paramMap) {
		try {
			return client.findOnSaleTicketByPageCount(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean addOnSaleTicketInfo(OnSaleTicket info) {
		try {
			return client.addOnSaleTicketInfo(info);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public Map findTicketInfoStrById(long id) {
		try {
			return JSON.parseObject(client.findTicketInfoStrById(id));
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List getRelatedTicketsByTicketId(long id) {
		try {
			Map<String, String> param = new HashMap<>();
			param.put("id", id+"");
			param.put("pageNo", "1");
			param.put("pageSize", "9999");
			return JSON.parseArray(client.getRelatedTicketsByTicketId(param));
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	public boolean bindTicketTicketRelation(List<Map<String, String>> list) {
		try {
			return client.addRelatedTicketDetail(list);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean delRelatedTicketDetail(Map<String, String> paramMap) {
		try {
			return client.delRelatedTicketDetail(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int getRelatedTicketsCountByTicketId(long ticketId) {
		try {
			Map<String, String> paramMap = new HashMap<>();
			paramMap.put("id", ticketId+"");
			return client.getRelatedTicketsCountByTicketId(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean updateOnSaleIsOK(String onSaleId, int isOk) {
		try {
			return client.updateOnSaleIsOK(onSaleId, isOk);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean updateOnSaleIsState(String onSaleId, int state) {
		try {
			return client.updateOnSaleIsState(onSaleId, state);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int findTicketAdsByPageCount(Map<String, String> paramMap) {
		try {
			return client.findTicketAdsByPageCount(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List<TicketAds> findTicketAdsByPage(Map<String, String> paramMap) {
		try {
			return client.findTicketAdsByPage(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public List findTicketAdsStrByPage(Map<String, String> paramMap) {
		try {
			return JSON.parseArray(client.findTicketAdsStrByPage(paramMap));
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean addTicketAds(TicketAds bean) {
		try {
			return client.addTicketAds(bean);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public boolean updateTicketAds(TicketAds bean) {
		try {
			return client.updateTicketAds(bean);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	/*public List<String> getImageListById(long id) throws TException {
		return client.getImageListById(id);
	}*/

	/*public String findTicketsByPage(Map<String, String> paramMap)
			throws TException {
		return client.findTicketsByPage(paramMap);
	}*/

	/*public int findTicketsByPageCount(Map<String, String> condition)
			throws TException {
		return client.findTicketsByPageCount(condition);
	}

	public boolean deleteTicketById(long id) throws TException {
		return client.deleteTicketById(id);
	}*/
	
	
	
	
	/*public List findTicketsByPage(Map<String, String> paramMap) {
		Map ticket1 = Maps.newHashMap("ticket_info_id", "1", "scenic_id", "1", "DictionaryId", "1", "name", "北京动物园", "description", "北京动物园"
				, "buy_note", "购买须知", "buyin_price", "25", "list_price", "35", "inventory", "200", "from_time", "2014-09-02 14:14:24"
				, "end_time", "2014-09-02 14:14:27", "address_detail", "西直门", "isOK", "1");
		Map ticket2 = Maps.newHashMap("ticket_info_id", "2", "scenic_id", "1", "DictionaryId", "1", "name", "北京欢乐谷", "description", "北京欢乐谷"
				, "buy_note", "购买须知", "buyin_price", "25", "list_price", "35", "inventory", "150", "from_time", "2014-09-02 14:14:24"
				, "end_time", "2014-09-02 14:14:27", "address_detail", "望京", "isOK", "1");
		Map ticket3 = Maps.newHashMap("ticket_info_id", "3", "scenic_id", "1", "DictionaryId", "1", "name", "北戴河野生动物园", "description", "北戴河野生动物园"
				, "buy_note", "购买须知", "buyin_price", "50", "list_price", "100", "inventory", "300", "from_time", "2014-09-02 14:14:24"
				, "end_time", "2014-09-02 14:14:27", "address_detail", "北戴河", "isOK", "1");
		Map ticket4 = Maps.newHashMap("ticket_info_id", "4", "scenic_id", "1", "DictionaryId", "1", "name", "秦皇岛乐岛海上乐园", "description", "秦皇岛乐岛海上乐园"
				, "buy_note", "购买须知", "buyin_price", "60", "list_price", "120", "inventory", "488", "from_time", "2014-09-02 14:14:24"
				, "end_time", "2014-09-02 14:14:27", "address_detail", "秦皇岛", "isOK", "1");
		return Lists.newArrayList(ticket1, ticket2, ticket3, ticket4);
	}
	
	public Map findSceneById(long id) {
		//string-->map JSON.parseObject("");
		//map-->string JSON.toJSONString(Maps.newHashMap());
		return Maps.newHashMap("scenic_id", "1", "name", "北京动物园", "description", "北京动物园", "list_price", "20", "open_time"
				, "2014-08-13 21:04:54", "end_time", "2014-08-13 21:04:58", "traffic_info", "堵车", "GPS_lat", "166.123", "GPS_lng"
				, "2.333", "caution", "注意啊", "adm_div_id", "10010201", "sce_address", "西直门", "DictionaryId", "1", "isOK", "1");
	}/*
	
	public Map findTicketById(long id) {
		return Maps.newHashMap("ticket_info_id", "1", "scenic_id", "1", "DictionaryId", "1", "name", "北京动物园", "description", "北京动物园"
				, "buy_note", "购买须知", "buyin_price", "25", "list_price", "35", "inventory", "200", "from_time", "2014-09-02 14:14:24"
				, "end_time", "2014-09-02 14:14:27", "address_detail", "西直门", "isOK", "1");
	}/*
	
	public List findImgsByTicketId(long id) {
		return Lists.newArrayList("/cloud/ticket/20140905/09984abc171d40218018f6b3484f64a7.png"
				, "/cloud/ticket/20140905/3345014cced94302a5714dcfa46e7c85.png", "/cloud/ticket/20140905/7b2f125b917646f4a80b71babea05cc0.png");
	}/*
*/
}
